home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / BASICDOC.ZIP / BASICDOC.TXT next >
Text File  |  1995-06-17  |  11KB  |  234 lines

  1.  
  2.       ╒═══════════════════════════════════════════════════════════════╗
  3.       │■                                                            ■ ║
  4.       │                                                               ║
  5.       │  █████████░                   ██░                             ║
  6.       │  ██░    ██░ ██░   ██░ ██████░ ██░     ████████░ ██░     ██░   ║
  7.       │  ██░    ██░ ██░   ██░   ██░   ██░     ██░   ██░ ██░     ██░   ║
  8.       │  ██░    ██░ ██░   ██░   ██░   ██░     ████████░ ██░     ██░   ║
  9.       │  ██░    ██░ ██░   ██░   ██░   ██░     ██░   ██░ ██░ ██░ ██░   ║
  10.       │  █████████░ ████████░   ██░   ██████░ ██░   ██░  ███░ ███░    ║
  11.       │                                                               ║
  12.       │                        T ∙ R ∙ I ∙ A ∙ D                      ║
  13.       │■                                                            ■ ║
  14.       └───────────────────────────────────────────────────────────────╜
  15.                                ╔══════════════╗
  16.                                ║ ∙ PRESENTS ∙ ║
  17.                                ╚══════════════╝
  18.  
  19.                       Mode 13h Documentary Version 1.5
  20. ──────────────────────────────────────────────────────────────────────────────
  21.   Written By : Vulture                    Total Files  : 2
  22.   File Type  : Textfile                   Release Date : 17th of June 1995
  23.   Difficulty : Basic level                Filename     : BASICDOC.ZIP
  24. ──────────────────────────────────────────────────────────────────────────────
  25.  
  26. Welcome to yet another textfile by Vulture. I decided to write this file for
  27. all starting gfx coders coz I think it is very important to fully understand
  28. the basics. When I started to code graphics, I lost a lotta time just because
  29. I did not acctually knew what I was doing. Maybe this text will prevend this
  30. to happen again to other coders. This file was written for those of you who
  31. really want to get into vga-programming. I will be using plain Turbo Pascal
  32. and just a very small bit of assembler. It won't be very hard to understand.
  33. Yeah, I know there are already lots of trainers on this subject available but
  34. I also have experienced that it can be helpful to read various trainers on the
  35. same subject. Anyway, off we go....
  36.  
  37. =-=-=-=-=-=-=-=-=-=-=-=-=-= MODE 13H DOCUMENTARY =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  38.  
  39. In this document I will cover:
  40.  
  41. A. How to enter mode 13h
  42. B. Memory layout
  43. C. Place yar first pixels
  44. D. Example program
  45. E. Closing words
  46.  
  47. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  48.  
  49. A. HOW TO ENTER MODE 13H.
  50.  
  51. Ok, let's start. I will refer to mode 13h as MCGA mode coz this is the
  52. official name of the mode. The MCGA mode has a resolution of 320*200*256
  53. which means that we have 320 pixels along the X-axis and 200 pixels along
  54. the Y-axis. We also have no less than 256 colors to our disposal. Great!
  55. Now, how do we get into this great grafix mode? I mean, before we can do
  56. any graphic related stuff such as plotting pixels, we have to get into the
  57. videomode first. This is done using a bit of inline assembler. Here it is:
  58.  
  59. Procedure VideoMode(Mode: Byte); Assembler;  { Used to switch videomodes }
  60. Asm
  61.    mov  ah,00             { Set high byte of ax }
  62.    mov  al,Mode           { Select the mode here }
  63.    int  10h               { Call video interrupt }
  64. End;
  65.  
  66. The 'Mode' variable should contain $13 if you want to get in gfx-mode or else
  67. $3 if you want to get to text-mode. Pretty easy, uh? :)
  68.  
  69. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  70.  
  71. B. MEMORY LAYOUT of MODE 13H.
  72.  
  73. Right, now we have entered the videomode 13h. What we need to know now is
  74. the way things are organized in the vga memory when using MCGA mode.
  75. This is acctually very easy.
  76.  
  77. Layout of a VGA-mode 13h screen:
  78.  
  79.                                   X-AXIS
  80.  
  81.       0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .319
  82.       320. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .639
  83.  Y    640. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .959
  84.  A    960. . . . . .
  85.  X
  86.  I                               etc etc etc
  87.  S
  88.                                                        . . . . . . .63679
  89.       63680. . . . . . . . . . . . . . . . . . . . . . . . . . . . .63999
  90.  
  91. So, as you can see here, the VGA memory in this mode is lineair. To be more
  92. exact: When you show pixel 319, you will see a pixel in the upperRIGHT corner
  93. of the screen. But when you fill pixel 320, you will then see a pixel in the
  94. upperLEFT corner on line 1! (know that the upperleft corner is location 0,0)
  95. But in vga memory these values are situated next to eachother. It may sound a
  96. little strange at this moment but you'll get the hang of it soon. Think of it
  97. as one long string. Range from 0 to 63999 (64000 total). This gives us the 320
  98. pixels on the x-axis and 200 on the y-axis.
  99.  
  100. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  101.  
  102. C. PLACING PIXELS ON THE SCREEN.
  103.  
  104. You can place pixels on the screen by pointing to the spot you want filled
  105. and giving the color of the dot. The color is a number between 0 and 255 coz
  106. we have 256 colors. Now, suppose you want to place a pixel in exactly the
  107. middle of the screen with color blue. What you have to know then is the X and
  108. Y-value of that position and the colorvalue of blue. Well, the X-value should
  109. be 160 since 320/2=160 is the middle of a line. Our Y-value should be 100 coz
  110. 200/2 is 100. The colorvalue of blue is 1 (when using the standard pallette).
  111. When you know all this, you must calculate the position on the screen since
  112. the screen layout is lineair and does not work with X and Y values. This is
  113. the formula to do that: Y*320+X. Think about it. It really should be very
  114. easy to understand. So easy infact, that I'm not gonna explain it here...
  115. (hehe, evil grin:))
  116.  
  117. Anyway, here's a pascal procedure which plots a pixel at X,Y:
  118.  
  119. Procedure Putpixel(X,Y: Integer; Col: Byte);
  120. Begin
  121.   Mem[VGA:(Y*320)+X]:=Col;
  122. End;
  123.  
  124. Why don't you try X=160, Y=100 and Col=1? You'll see what I mean...
  125. The 'VGA' is a constant which resembles the VGA-segment $a000. This is another
  126. aspect to be understood well. To put it simply it means that 'VGA' points to
  127. the start of the screen. When you plot a pixel you are using a segment and an
  128. offset. The VGA segment is $a000. So, to be more exact: $a000:0000 represents
  129. the upperleft corner of the screen. When you are pointing to a certain pixel,
  130. you are pointing to it's offset from the segment. Think of it this way: The
  131. segment is the start of the screen and the offset is the exact place within
  132. this segment. As said before, you can only adress 64000 pixels in MCGA mode.
  133. (Hmm, acctually 64kB can be adressed but the last bytes are not shown)
  134. Well, you should create a constant 'VGA' by doing this:
  135.  
  136. Const VGA = $a000;
  137.  
  138. The above putpixel procedure isn't real fast but it is fast enough for our
  139. purposes right now. If you really want a fast one, you should convert it to
  140. assembler. That's what I have done myself. Hee, if you have troubles coding
  141. in assembler, contact me at one of the Outlaw distros. I'll give you my own
  142. putpixel procedure to work with.
  143.  
  144. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  145.  
  146. D. SAMPLE PROGRAM.
  147.  
  148. Now follows a sample-program which demonstrates the putpixel procedure. Play
  149. with it and learn. . . You could try to draw horizontal and vertical lines...
  150.  
  151. Program MCGASample;       { Demonstrates the basic mode 13h }
  152.  
  153. Uses Crt;
  154.  
  155. Const VGA = $a000;        { The VGA segment }
  156.  
  157. Var Ch: Char;
  158.  
  159. Procedure VideoMode(Mode: Byte); Assembler;  { Used to switch videomodes }
  160. Asm
  161.    mov  ah,00             { Set high byte of ax }
  162.    mov  al,Mode           { Select the mode here }
  163.    int  10h               { Call video interrupt }
  164. End;
  165.  
  166. Procedure Putpixel (X,Y: Integer; Col: Byte);
  167. Begin                     { Puts a pixel at X,Y with color Col }
  168.   Mem[VGA:(Y*320)+X] := Col;
  169. End;
  170.  
  171. Begin
  172.   RandoMize;
  173.   VideoMode($13);         { Get in graphics mode }
  174.   Repeat
  175.     PutPixel(Random(320), Random(200), Random(255));
  176.   Until KeyPressed;       { Draw pixels on the screen until a key is pressed }
  177.   Ch := Readkey;
  178.   VideoMode($3);          { Get in text mode }
  179. End.
  180.  
  181. That's it...
  182.  
  183. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  184.  
  185. E. CLOSING WORDS.
  186.  
  187. Well, this is all I was about to explain in this short tutorial. You can now
  188. get into the vgamode and plot pixels all across the screen. You should be able
  189. to understand the memory layout in this mode and also the basics behind the
  190. segment and offset things. Take a look at the sample program for a quick
  191. example. It's all pretty basic stuff but be sure to fully understand it all
  192. before moving on to all kinds of cewl fx you want to create. You can loose a
  193. lot of time when you are just fooling around a bit. I know what I'm talking
  194. about... :)
  195.  
  196. This document was written by Vulture. Although many things concerning MCGA
  197. have not been discussed here, this text should be of some help to you. It's
  198. enough to get you started. Maybe in the future updated versions of this file
  199. will be released but that remaines to be seen.
  200.  
  201. Hmm, well, the following cr*p is supposed to be stated so here we go:
  202. I (Vulture) take no responsibility for any mistakes found in this document.
  203. So use at your own risk. If you spot errors or have something to add to the
  204. text, don't hesitate to contact me. Phew, that's that... :)
  205.  
  206. Wanna contact Outlaw for any reason? Then leave mail at one of our distros.
  207. Don't hestitate to mail Outlaw, coz we like to chat with otha scene-people.
  208.  
  209.  
  210.           Signed:   Vulture / Outlaw Triad
  211.  
  212.  
  213. ─────────────────────────┬───────────────────────┬────────────────────────────
  214.  Outlaw Triad Distros :  │  Greetz from Outlaw:  │  Releases sofar:
  215. ─────────────────────────┼───────────────────────┼────────────────────────────
  216.                          │                       │
  217.  ■    Blue Thunder   ■   │   - DemoLisher        │   ■ MESSAGE  (dosscroller)
  218.  ■ +31 (0)36-5346967 ■   │   - ThunderHawk       │
  219.                          │   - Ash               │   ■ VGA-VUL1 (sources)
  220.                          │   - The Machine       │
  221.  ■     FireHouse     ■   │   - X∙N∙TRiC          │   ■ CHAINDOC (textfile)
  222.  ■ +31 (0)58-2661590 ■   │   - Utter Chaos       │
  223.                          │   - Crusher           │   ■ VGA-VUL2 (sources)
  224.                          │                       │
  225.                          │   - Critical          │   ■ BASICDOC (textfile)
  226.      Open for more!      │   - Da Frisian Force  │
  227.                          │   - Tribal            │   + various bbs-intros
  228.                          │                       │
  229. ─────────────────────────┴───────────────────────┴────────────────────────────
  230.  
  231.                    ■ (C) 1995  O∙U∙T∙L∙A∙W   T∙R∙I∙A∙D ■
  232.  
  233. ──────────────────────────────────────────────────────────────────────────────
  234.